// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Lg/Unlit/Transparent Colored-Shadow1"
{
	Properties
	{
		_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
		_ShadowColor("ShadowColor",Color) = (0,0,0,0.5)
		_LightPos("LightPos",vector) = (0,0,1,0)
		_LightRange("LightRange",Range(0,5)) = 1
	}
	
	SubShader
	{
		LOD 200

		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
			"DisableBatching" = "True"
			"PreviewType" = "Plane"
		}

		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Offset -1, -1
			Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag			
			#include "UnityCG.cginc"

			// Unity 4 compatibility
			#ifndef UNITY_VERTEX_INPUT_INSTANCE_ID
			#define UNITY_VERTEX_INPUT_INSTANCE_ID
			#define UNITY_VERTEX_OUTPUT_STEREO
			#define UNITY_SETUP_INSTANCE_ID(v)
			#define UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(i)
			#define UnityObjectToClipPos(v) UnityObjectToClipPos(v)
			#endif

			sampler2D _MainTex;
			float4 _MainTex_ST;
			fixed4 _ShadowColor;
			float4 _LightPos;
			float _PlaneHeight, _LightRange;
	
			struct appdata_t
			{
				float4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
				fixed4 color : COLOR;
				UNITY_VERTEX_INPUT_INSTANCE_ID
			};
	
			struct v2f
			{
				float4 vertex : SV_POSITION;
				half2 texcoord : TEXCOORD0;
				fixed4 color : COLOR;
				UNITY_VERTEX_OUTPUT_STEREO
			};
	
			v2f o;

			v2f vert (appdata_t v)
			{
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				float2 offset = v.vertex.xy -_LightPos.xy;
				float2 finalOffset = offset * (_LightPos.z / (_LightPos.z - 0.1));
				v.vertex.xy = _LightPos.xy + finalOffset;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.texcoord = v.texcoord;
				o.color = v.color;
				return o;
			}
				
			fixed4 frag(v2f IN) : SV_Target
			{
				float f = distance(IN.texcoord - 0.5,_LightPos.xy);
				float atten = max(0, 1 - pow(f / _LightRange,2));
				fixed maskAlpha = tex2D(_MainTex, IN.texcoord).a * atten;
				_ShadowColor.a *= maskAlpha;
				return _ShadowColor;
			}
			ENDCG
		}
		
		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Offset -1, -1
			Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag			
			#include "UnityCG.cginc"

			// Unity 4 compatibility
			#ifndef UNITY_VERTEX_INPUT_INSTANCE_ID
			#define UNITY_VERTEX_INPUT_INSTANCE_ID
			#define UNITY_VERTEX_OUTPUT_STEREO
			#define UNITY_SETUP_INSTANCE_ID(v)
			#define UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(i)
			#define UnityObjectToClipPos(v) UnityObjectToClipPos(v)
			#endif

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float4 _LightPos;
	
			struct appdata_t
			{
				float4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
				fixed4 color : COLOR;
				UNITY_VERTEX_INPUT_INSTANCE_ID
			};
	
			struct v2f
			{
				float4 vertex : SV_POSITION;
				half2 texcoord : TEXCOORD0;
				fixed4 color : COLOR;
				UNITY_VERTEX_OUTPUT_STEREO
			};
	
			v2f o;

			v2f vert (appdata_t v)
			{
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.texcoord = v.texcoord;
				o.color = v.color;
				return o;
			}
				
			fixed4 frag(v2f IN) : SV_Target
			{
				return tex2D(_MainTex, IN.texcoord ) * IN.color;
			}
			ENDCG
		}

		

	}

}
